<?php

require_once "aochat.php";

class bot extends AOChat {
	function __construct($nombre, $db, $callback, $vars, $settings) {
		$this->nombre = $nombre;

		$this->callback = $callback;
		$this->cbargs = $this;

		$this->settings = $settings;
		$this->vars = $vars;
	}

	function connectAO($login, $password) {
		$this->disconnect();

		// Choose Server
		if($this->vars["dimension"] == 1) {
			$server = "chat.d1.funcom.com";
			$port = 7012;
		} elseif($this->vars["dimension"] == 2) {
			$server = "chat.d2.funcom.com";
			$port = 7012;
		} elseif($this->vars["dimension"] == 3) {
			$server = "chat.d3.funcom.com";
			$port = 7013;
		} elseif($this->vars["dimension"] == 4) {
			$server = "chat.dt.funcom.com";
			$port = 7012;
		} else {
			echo "\n\n\n\n\n\n\n\n\n\n\n\n\n";
			echo "		    	  No valid Server to connect with!\n";
			echo "		       Available dimensions are 1, 2, 3 and 4!";
			echo "\n\n\n\n\n\n\n\n\n\n\n\n";
			sleep(10);
			die();
		}

		// Begin the login process
		echo "\n\n\n\n\n\n\n\n\n\n\n\n\n";
		echo "		    	  Connecting to AO Server...\n";
		echo "		    	     ($server)";
		echo "\n\n\n\n\n\n\n\n\n\n\n\n";
		$this->connect($server, $port);
		sleep(2);
		if($this->state != "auth") {
			echo "\n\n\n\n\n\n\n\n\n\n\n\n\n";
			echo "		    	  Connection to AO Servers failed!\n";
			echo "		     Pls check your Internetconnection and Firewall";
			echo "\n\n\n\n\n\n\n\n\n\n\n\n";
			sleep(10);
			die();
		}

		echo "\n\n\n\n\n\n\n\n\n\n\n\n\n";
		echo "		    	  Authenticate login data...\n";
		echo "\n\n\n\n\n\n\n\n\n\n\n\n";
		$this->authenticate($login, $password);
		sleep(2);

		if($this->state != "login") {
			echo "\n\n\n\n\n\n\n\n\n\n\n\n\n";
			echo "		    	  Authenticating of your data failed!\n";
			echo "		          Pls check your Account Informations!";
			echo "\n\n\n\n\n\n\n\n\n\n\n\n";
			sleep(10);
			die();
		}

		echo "\n\n\n\n\n\n\n\n\n\n\n\n\n";
		echo "		    	  Logging in {$this->vars["name"]}...\n";
		echo "\n\n\n\n\n\n\n\n\n\n\n\n";
		$this->login($this->vars["name"]);
		sleep(2);

		if($this->state != "ok") {
			echo "\n\n\n\n\n\n\n\n\n\n\n\n\n";
			echo "		    	Logging in of {$this->vars["name"]} failed!\n";
			echo "		    Pls check if this char exists on the Account!";
			echo "\n\n\n\n\n\n\n\n\n\n\n\n";
			sleep(10);
			die();
		}

		echo "\n\n\n\n\n\n\n\n\n\n\n\n\n";
		echo "		    	  All Systems ready....\n";
		echo "\n\n\n\n\n\n\n\n\n\n\n\n";
		sleep(2);

		// Set cron timers
		$this->vars["2sec"] 			= time() + $this->settings["CronDelay"];
		$this->vars["1min"] 			= time() + $this->settings["CronDelay"];
		$this->vars["1hour"] 			= time() + $this->settings["CronDelay"];
		$this->vars["24hours"]			= time() + $this->settings["CronDelay"];
		$this->vars["15min"] 			= time() + $this->settings["CronDelay"];

	}

	function processCallback($type, $args) {
		echo "#### Process callback! ####\n";
		echo "type: " . $type . "\n";
		echo "args: ";
		print_r($args);
		echo "\n";
		echo "########\n\n";
	}

	function crons() {
		echo "Crons ". $this->nombre ."!\n";
	}

	function connectedEvents() {
		echo "Connected events!\n";
	}
}

?>